package mysql

import (
	"fmt"
)

type Aonline struct {
	Id         uint `gorm:"primary_key"`
	IdAdmin    uint
	Ip         string
	LoginKey   string
	ActiveTime int32
	ExpireTime int32
	Address    string
	AddTime    int32
	UpdateTime int32
	AddDate    int
}

//这一步的意思是改表明的  默认表明是带s的
func (Aonline) TableName() string {
	return "k_admin_online"
}

func (a Aonline) GetAdminByToken(token string) (Aonline, error) {
	var anoline Aonline
	err := Db.Where("login_key = ?", token).Find(&anoline).Error
	if err != nil {
		fmt.Println("查询错误", err)
		return anoline, err
	}
	return anoline, err
}

func (a Aonline) Add (aonline Aonline)  {

	err := Db.Create(&aonline).Error
	if err != nil {
		fmt.Println("添加错误", err)
	}
}

func (a Aonline) Del(token string){

	var anoline Aonline
	err := Db.Where("login_key = ?",token).Delete(&anoline).Error
	if err != nil {
		fmt.Println("删除错误", err)
	}

}

func (a Aonline) DelById(adminId uint){

	var anoline Aonline
	err := Db.Where("id_admin = ?",adminId).Delete(&anoline).Error
	if err != nil {
		fmt.Println("删除错误", err)
	}

}